import axios from "axios";
// 创建实例
const request = axios.create({
  baseURL: "http://36.139.136.103:3000", //地址
  timeout: 5000, //请求时间
});
request.interceptors.request.use(
  (config) => {
    const token = window.localStorage.getItem("token");
    if (token != null) {
      // 直接在请求头使用，不需要Bearer
      config.headers.Authorizatio = token;
    }
    return config;
  },
  (error) => {
    return Promise.reject(error); //出现错误.....
  }
);
request.interceptors.response.use(
  function (
    // 响应拦截
    response
  ) {
    return response;
  },
  function (error) {
    return Promise.reject(error);
  }
);

export default request;
